<template>
  <div class="contentShadow">
    <el-input v-model="filename" placeholder="请输入您想要的文件名，比如成绩汇总.xlsx"
              style="margin-bottom: 30px"></el-input>
    <el-button size="small" type="primary" @click="exportStudentScore">导出学生成绩</el-button>
  </div>
</template>

<script>

import {downloadRequest, exportRequest} from "@/api/download";

export default {
  methods: {
    beforeUpload(file) {
      // console.log(file);
    },
    exportStudentScore() {
      exportRequest(this.filename).then((res) => {
        console.log(res)
      })
      downloadRequest(this.filename).then((res) => {
        // 创建 a 标签进行下载
        const url = window.URL.createObjectURL(new Blob([res]))
        const link = document.createElement('a')
        link.href = url
        link.setAttribute('download', this.filename)
        document.body.appendChild(link)
        link.click()
      })
    },
  },
  data() {
    return {
      filename: '',
    };
  }
}
</script>
